<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 农家乐
 * Created by PhpStorm.
 * User: 66diqiu-li
 * Date: 14-8-22
 * Time: 上午10:54
 */
class Trips_Index_module extends CI_Module
{
    /**
     * 构造函数
     */
    private $sid ;
    private $data ;
    private $sitename;

    public function __construct(){
        parent::__construct();
        $this->sid = $GLOBALS['sid'];
        $this->data = $GLOBALS['config'];
        $this->load->model('admin.area_model');
        $this->load->model('trips.trips_model');
        $this->load->model('admin.area_model');
        
        $this->load->model('comment.comment_model');
        $this->sitename = $GLOBALS['config']['sitename'];
    }

    /**
     * 农家乐列表页面
     */
    public function index(){

        $param = $this->uri->segment(2);
        $param = str_replace(array('list_'), '', $param);
        @list($cat_id, $area_id) = explode('_', $param);
        $cat_id = intval($cat_id);
        $area_id = intval($area_id);

        //查询条件
        $where = array('parent_id'=>12);
        $where['status'] = 0;

        //分类名称
        $trip_cat_row = $this->trips_model->category_by_id($cat_id?$cat_id:$where['parent_id']);

        //特色ID
        $cat_name = '农家乐';
        $area_name = SITECITYNAME;
        $cat_name_extend = $area_name_extend = '';
        if(!empty($cat_id)){
            $where['cat_id'] = $cat_id;
            $cat_name_extend = $trip_cat_row['name'];
        }

        //地区ID
        if(!empty($area_id)){
            $where['area_id'] = $area_id;
            $area_name_extend = str_replace(array('[',']'),'',$this->area_model->get_area_name(array($area_id)));
        }

        $data = array();
        $title = $area_name.$area_name_extend.$cat_name_extend.$cat_name;
        $keywords = $title;
        if($cat_name_extend)$keywords.= ','.$cat_name_extend;
        if($area_name_extend)$keywords.= ','.$area_name_extend;
        $keywords.= ",".SITECITYNAME.$cat_name;

        $desc = "{$title}，".SITECITYNAME."旅游网{$title}，为您提供{$title}和".SITECITYNAME."农家院预订，".SITECITYNAME."附近农家乐价格查询，涵盖{$title}房客房图片、用户真实点评及{$title}地址电话等信息。".SITECITYNAME."市旅游局";
        $data['params'] = array(
            'seo'=>array('title'=>$title.'_农家院_推荐_预订','keywords'=>$keywords,'desc'=>$desc),
            'nav'=>array('current'=>'agritainment'),
        );

        $page_config['perpage'] =12;   //每页条数
        $page_config['part']=2;//当前页前后链接数量
        $page_config['url']= "nongjiale/list_{$cat_id}_{$area_id}";//url
        $page_config['nowindex'] = $this->uri->segment(3)>0 ? $this->uri->segment(3):1;//当前页
        $page_config['total']   = $this->trips_model->get_index_count($where);
        $this->load->library('mypageclass');
        $this->mypageclass->initialize($page_config);
        $trips_list = $this->trips_model->get_index_trips_list($page_config['perpage'],$page_config['nowindex'],$where);
        $data['list'] = $trips_list;

        //特色列表
        $tese_list = $this->trips_model->get_index_cat_list($where);
        $data['tese_list'] = $tese_list;

        //地区列表
        $area = $this->trips_model->get_index_area_list($where);
        $area_list = array();
        if(!empty($area)){
            foreach($area as $val){
                $row = array();
                $row['area_id'] = $val['area'];
                $row['area_name'] = str_replace(array('[',']'),'',$this->area_model->get_area_name(array($val['area'])));
                $area_list[] = $row;
            }
        }
        $data['area_list'] = $area_list;

        $data['arg_get'] = array(
            'cat_id'=>$cat_id?$cat_id:'0',
            'area_id'=>$area_id?$area_id:'0',
        );


        //面包屑
        if($cat_id!=0||$area_id!=0)$bread[] = array('url'=>site_url('nongjiale'),'name'=>$area_name.$cat_name);
        $bread[] = array('name'=>$title);
        $data['bread'] = $bread;
        $this->load->view(TEMPLATE_NAME.'/index',$data);
    }

    /**
     * 农家乐详情页面
     * @param $id 农家乐ID
     */
    public function info($id){
        $data = array();
        //详情
        $row = $this->trips_model->get_index_info($id);
        $data['row'] = $row;
        $title = $row['subject'].'_预订_用户点评_地址_联系电话_照片';
        $keyword = "{$row['subject']},{$row['subject']}地址";
        $desc = "{$row['subject']}，".SITECITYNAME."旅游网{$row['subject']}地理位置优越，依山傍水、景色宜人、交通便利，私密性强。花园式小院，品农家大餐，赏秀美风景，这里就是您的快乐老家!".SITECITYNAME."市旅游局";
        $data['params'] = array(
            'seo'=>array('title'=>$title,'keywords'=>$keyword,'desc'=>$desc),
            'nav'=>array('current'=>'agritainment'),
        );
        $data['bread'] = array(
            array('url'=>site_url('nongjiale'),'name'=>SITECITYNAME.'农家乐'),
            array('name'=>$row['subject'])
        );
        $this->load->view(TEMPLATE_NAME.'/info',$data);
    }

    public function trips()
    {
        $sitecity = SITECITYNAME;
        $city_name = "";
        $province_name = "";
        $category_name = "" ;
        $extra_name = "最热" ;
        $data = array();
        $param = $this->uri->segment(2);
        $param = str_replace(array('list_'), '', $param);
        @list($province, $city, $category,$extra,$keywords) = explode('_', $param);
        $province = $data['province'] = intval($province);
        $city     = $data['city']     = intval($city);
        $category    = $data['category']    = intval($category);
        $extra    = $data['extra']    = intval($extra);
//        $keywords = $data['keywords'] = addslashes($keywords);
        $keywords = addslashes(trim(urldecode($keywords)));
        $data['keywords'] =$keywords = empty($keywords)?$this->site_keywords:urldecode($keywords);
        $data['categories_list'] = $this->trips_model->category_list('trips_count>0');
        if($province){
            $data['city_list'] = $this->area_model->get_area_by_id($province, 'code_level ASC, poi_code ASC');
        }else{
            $data['city_list'] = array();
        }
        /*组装筛选参数*/
        $where = array();
        $where['status'] = '0';
        //$where['sid'] = $this->sid ;
        if(!empty($province)){
            $where['province'] = $province ;
        }
        if(!empty($city)){
            $where['city'] = $city ;
        }
        if(!empty($category)){
            $where['category']=$category;
        }
        if(!empty($keywords)){
            $where['keywords']=$keywords;
        }
        if(!empty($extra)){
            $where['extra']=$extra;
            if($extra=='0') $extra_name = '最热' ;
            if($extra=='1') $extra_name = '最新' ;
        }
        if($city_name=$this->area_model->get_area_name(array($city)))
        {
            $city_name = str_replace(array('[',']'),'',$city_name);
        }
        if($province_name=$this->area_model->get_area_name(array($province)))
        {
            $province_name = str_replace(array('[',']'),'',$province_name);
        }

        if($category_res=$this->trips_model->category_by_id($category))
        {
            $category_name = $category_res['name'] ;
        }

        $page_config['perpage']=10;   //每页条数
        $page_config['part']=2;//当前页前后链接数量
        $page_config['url']= "/gonglve/list_{$province}_{$city}_{$category}_{$extra}";//url
        $page_config['nowindex'] = $this->uri->segment(3)>0 ? $this->uri->segment(3):1;//当前页
        $page_config['total'] = $this->trips_model->trips_count_2($where);
        $this->load->library('mypageclass');
        $this->mypageclass->initialize($page_config);
        $data['trips_list'] = $this->trips_model->trips_list_2($page_config['perpage'],$page_config['nowindex'],$where);

        foreach($data['trips_list'] as $k=>$v)
        {
            $data['trips_list'][$k]['data_uri'] = site_url('/gonglve/'.$v['id'].'.html');
            $data['trips_list'][$k]['file_url'] = empty($v['file_url'])?URLPRE.'static/public/images/nophoto.jpg':filter_img($v['file_url']);
            $data['trips_list'][$k]['crts'] = $data['trips_list'][$k]['upts'];
            if(!$v['author']){
                $data['trips_list'][$k]['author'] = '掌旅宝网络科技有限公司';
            }
        }
        $seo_query = $extra_name.$province_name.$city_name.$category_name ;
        $data['params'] = array(
            'seo'=>array(
                'title'=>$seo_query.'旅游攻略_'.$seo_query.'自助游攻略_自驾游'.($page_config['nowindex']>1?'_第'.$page_config['nowindex'].'页':''),
                'keywords'=>$seo_query.'旅游攻略',
                'desc'=>$seo_query.'旅游攻略，'.$this->sitename.'为您提供'.$seo_query.'旅游攻略信息，并提供'.$seo_query.'自助游酒店、线路、景点门票低价预订服务。'.SITECITYNAME.'旅游网',
            ),
            'nav'=>array(
                'current'=>'trips'
            )
        );
        $where = array(
        );
        $data['trips_recommend_ads'] = $this->trips_model->trips_list(10,1,$where, '', 'view DESC');
        $data['city_name'] = $city_name;
        $data['province_name'] = $province_name;
        $data['bread'] = '' ;
        $uri_param = $this->uri->segment(2);
        $bread = array(array('name'=>'游记攻略','url'=>site_url('gonglve')));
        if(!empty($uri_param)){
            $bread[1] = array('name'=>$seo_query.'游记攻略');
        }
        $data['bread'] = $bread;
        $data['seo_query'] = $seo_query ;

        $data['cat_list'] = array('0'=>'全部','1'=>'美食',2=>'住宿',3=>'旅游景点',4=>'购物',5=>'娱乐',6=>'租车');
        $this->load->view(TEMPLATE_NAME.'/trips_list',$data);
    }

    public function bendiyou()
    {
        $sitecity = SITECITYNAME;
        $city_name = "";
        $province_name = "";
        $category_name = "" ;
        $extra_name = "最热" ;
        $data = array();
        $param = $this->uri->segment(2);
        $param = str_replace(array('list_'), '', $param);
        @list($province, $city, $category,$extra,$keywords) = explode('_', $param);
        $province = $data['province'] = intval($province);
        $city     = $data['city']     = intval($city);
        $category    = $data['category']    = intval($category);
        $extra    = $data['extra']    = intval($extra);
//        $keywords = $data['keywords'] = addslashes($keywords);
        $keywords = addslashes(trim(urldecode($keywords)));
        $data['keywords'] =$keywords = empty($keywords)?$this->site_keywords:urldecode($keywords);
        $data['categories_list'] = $this->trips_model->category_list('trips_count>0');
        if($province){
            $data['city_list'] = $this->area_model->get_area_by_id($province, 'code_level ASC, poi_code ASC');
        }else{
            $data['city_list'] = array();
        }
        /*组装筛选参数*/
        $where = array();
        $where['sid'] = $this->sid;

        $where['status'] = '0';
        //$where['sid'] = $this->sid ;
        if(!empty($province)){
            $where['province'] = $province ;
        }
        if(!empty($city)){
            $where['city'] = $city ;
        }
        if(!empty($category)){
            $where['category']=$category;
        }
        if(!empty($keywords)){
            $where['keywords']=$keywords;
        }
        if(!empty($extra)){
            $where['extra']=$extra;
            if($extra=='0') $extra_name = '最热' ;
            if($extra=='1') $extra_name = '最新' ;
        }
        if($city_name=$this->area_model->get_area_name(array($city)))
        {
            $city_name = str_replace(array('[',']'),'',$city_name);
        }
        if($province_name=$this->area_model->get_area_name(array($province)))
        {
            $province_name = str_replace(array('[',']'),'',$province_name);
        }

        if($category_res=$this->trips_model->category_by_id($category))
        {
            $category_name = $category_res['name'] ;
        }

        $page_config['perpage']=10;   //每页条数
        $page_config['part']=2;//当前页前后链接数量
        $page_config['url']= "/bendiyou/list_{$province}_{$city}_{$category}_{$extra}";//url
        $page_config['nowindex'] = $this->uri->segment(3)>0 ? $this->uri->segment(3):1;//当前页
        $page_config['total'] = $this->trips_model->trips_count_2($where);
        $this->load->library('mypageclass');
        $this->mypageclass->initialize($page_config);
        $data['trips_list'] = $this->trips_model->trips_list_2($page_config['perpage'],$page_config['nowindex'],$where);

        foreach($data['trips_list'] as $k=>$v)
        {
            $data['trips_list'][$k]['data_uri'] = site_url('/gonglve/'.$v['id'].'.html');
            $data['trips_list'][$k]['file_url'] = empty($v['file_url'])?URLPRE.'static/public/images/nophoto.jpg':filter_img($v['file_url']);
            $data['trips_list'][$k]['crts'] =$data['trips_list'][$k]['upts'];
            if(!$v['author']){
                $data['trips_list'][$k]['author'] = '掌旅宝网络科技有限公司';
            }
        }
        $seo_query = $extra_name.$province_name.$city_name.$category_name ;
        $data['params'] = array(
            'seo'=>array(
                'title'=>$seo_query.'旅游攻略_'.$seo_query.'自助游攻略_自驾游'.($page_config['nowindex']>1?'_第'.$page_config['nowindex'].'页':''),
                'keywords'=>$seo_query.'旅游攻略',
                'desc'=>$seo_query.'旅游攻略，'.$this->sitename.'为您提供'.$seo_query.'旅游攻略信息，并提供'.$seo_query.'自助游酒店、线路、景点门票低价预订服务。'.SITECITYNAME.'旅游网',
            ),
            'nav'=>array(
                'current'=>'bendiyou'
            )
        );
        $where = array(
        );
        $data['trips_recommend_ads'] = $this->trips_model->trips_list(10,1,$where, '', 'view DESC');
        $data['city_name'] = $city_name;
        $data['province_name'] = $province_name;
        $data['bread'] = '' ;
        $uri_param = $this->uri->segment(2);
        $bread = array(array('name'=>'游记攻略','url'=>site_url('gonglve')));
        if(!empty($uri_param)){
            $bread[1] = array('name'=>$seo_query.'游记攻略');
        }
        $data['bread'] = $bread;
        $data['seo_query'] = $seo_query ;

        $data['cat_list'] = array('0'=>'全部','1'=>'美食',2=>'住宿',3=>'旅游景点',4=>'购物',5=>'娱乐',6=>'租车');
        $this->load->view(TEMPLATE_NAME.'/bendi',$data);
    }

    public function trip_profile($id)
    {
        $data = $this->trips_model->get_trips_by_id($id);
        $data['message'] = filter_content($data['message']);
        $data['crts'] = $data['upts'];
        if(!$data['author']){
            $data['author'] = '掌旅宝网络科技有限公司';
        }
        $data['params'] = array(
            'seo'=>array(
                'title'=>$data['subject'].'旅游攻略',
                'keywords'=>$data['subject'].'旅游攻略',
                'desc'=>$data['subject'].'旅游攻略，'.$this->sitename.'拥有数百万真实游记，寻找精彩旅游攻略，尽在'.SITECITYNAME.'旅游网。'
            ),
            'nav'=>array(
                'current'=>'trips'
            )
        );
        $data['trips_recommend_ads'] = $this->trips_model->trips_list(10,1,$where, '', 'view DESC');
        $this->load->view(TEMPLATE_NAME.'/trips_profile',$data);
    }

    /**
     * 攻略娱乐频道页
     */
    public function yule(){
        $data = array();
        $where = array('category'=>'5','status'=>0);
        $page_config['perpage']=6;   //每页条数
        $page_config['part']=2;//当前页前后链接数量
        $page_config['url']= "gonglve/yule";//url
        $page_config['nowindex'] = $this->uri->segment(3)>0 ? $this->uri->segment(3):1;//当前页
        $page_config['total'] = $this->trips_model->trips_count_2($where);
        $this->load->library('mypageclass');
        $this->mypageclass->initialize($page_config);
        $data['trips_list'] = $this->trips_model->trips_list_2($page_config['perpage'],$page_config['nowindex'],$where);
        foreach($data['trips_list'] as $k=>$v)
        {
            $data['trips_list'][$k]['data_uri'] = site_url('gonglve/'.$v['id'].'.html');
            $data['trips_list'][$k]['file_url'] = empty($v['file_url'])?URLPRE.'static/public/images/nophoto.jpg':filter_img($v['file_url']);
            $data['trips_list'][$k]['crts'] =$data['trips_list'][$k]['upts'];
            if(!$v['author']){
                $data['trips_list'][$k]['author'] = '掌旅宝网络科技有限公司';
            }
        }
        $data['params'] = array(
            'seo'=>array(
                'title'=>'娱乐攻略',
                'keywords'=>'娱乐攻略',
                'desc'=>'娱乐攻略，'.$this->sitename.'拥有数百万真实游记，寻找精彩旅游娱乐攻略，尽在'.SITECITYNAME.'旅游网。'
            ),
            'nav'=>array(
                'current'=>''
            )
        );
        $bread = array(array('name'=>'娱乐攻略'));
        $data['bread'] = $bread;
        $this->load->view(TEMPLATE_NAME.'/yule',$data);
    }
    /**
     * 攻略购物频道页
     */
    public function gouwu(){
        $data = array();
        $where = array('category'=>'4','status'=>0);
        $page_config['perpage']=6;   //每页条数
        $page_config['part']=2;//当前页前后链接数量
        $page_config['url']= "gonglve/gouwu";//url
        $page_config['nowindex'] = $this->uri->segment(3)>0 ? $this->uri->segment(3):1;//当前页
        $page_config['total'] = $this->trips_model->trips_count_2($where);
        $this->load->library('mypageclass');
        $this->mypageclass->initialize($page_config);
        $data['trips_list'] = $this->trips_model->trips_list_2($page_config['perpage'],$page_config['nowindex'],$where);
        foreach($data['trips_list'] as $k=>$v)
        {
            $data['trips_list'][$k]['data_uri'] = site_url('gonglve/'.$v['id'].'.html');
            $data['trips_list'][$k]['file_url'] = empty($v['file_url'])?URLPRE.'static/public/images/nophoto.jpg':filter_img($v['file_url']);
            $data['trips_list'][$k]['crts'] =$data['trips_list'][$k]['upts'];
            if(!$v['author']){
                $data['trips_list'][$k]['author'] = '掌旅宝网络科技有限公司';
            }
        }
        $data['params'] = array(
            'seo'=>array(
                'title'=>'购物攻略',
                'keywords'=>'购物攻略',
                'desc'=>'购物攻略，'.$this->sitename.'拥有数百万真实游记，寻找精彩旅游购物攻略，尽在'.SITECITYNAME.'旅游网。'
            ),
            'nav'=>array(
                'current'=>''
            )
        );
        $bread = array(array('name'=>'购物攻略'));
        $data['bread'] = $bread;
        $this->load->view(TEMPLATE_NAME.'/gouwu',$data);
    }

    /**
     * 美食页面
     */
    public function meishi(){
        $data['params'] = array(
            'seo'=>array(
                'title'=>'美食攻略',
                'keywords'=>'美食攻略',
                'desc'=>'美食攻略，'.$this->sitename.'拥有数百万真实游记，寻找精彩旅游美食攻略，尽在'.SITECITYNAME.'旅游网。'
            ),
            'nav'=>array(
                'current'=>''
            )
        );
        $bread = array(array('name'=>'美食攻略'));
        $data['bread'] = $bread;
        $this->load->view(TEMPLATE_NAME.'/meishi',$data);
    }

}